package com.itlong.cloud.controller.logger;

import com.itlong.cloud.POJO.DTO.operate.OperateLoggerDeveloperLogGetPageDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateUserFaceInfoPageDTO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.operate.OperateDeveloperLogVO;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.AuthAccessRequired;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.noncore.operate.IOperateDeveloperLogServiceClient;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.page.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * <desc>
 *      运营-日志管理-操作日志管理控制器
 * </desc>
 *
 * @createDate 2018/04/10
 */
@RestController
@RequestMapping("/logger/developerLog")
public class OperateLoggerDeveloperLogController extends BaseController {
    @Autowired
    IOperateDeveloperLogServiceClient iOperateDeveloperLogServiceClient;


    /**
     * <desc>
     *      获取分页列表
     * </desc>
     *
     * @param dto 查询参数DTO
     * @return
     * @author Qiang.S
     * @createDate 2018/12/18
     */
    @RequestMapping(path = "getDeveloperLogByPage",method = RequestMethod.POST)
    @ResponseBody
    @AuthAccessRequired
    public Object getDeveloperLogByPage(OperateLoggerDeveloperLogGetPageDTO dto){
        MessageVO messageVO;
        try {
            HttpServletRequest request=((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            dto= HttpProtocolUtil.parseRequestParamToDTO(OperateLoggerDeveloperLogGetPageDTO.class,request);
            Page<OperateDeveloperLogVO> page=iOperateDeveloperLogServiceClient.getDeveloperLogByPage(dto);
            messageVO=new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),page);

        } catch (Exception e) {
            throw new DataAccessException("【运营_日志管理_开发者日志getPage】获取分页列表失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      删除操作日志
     * </desc>
     *
     * @param logIds 逻辑ID字符串 ，号分隔
     * @return
     * @author Qiang.S
     * @createDate 2018/12/18
     */
    @AuthAccessRequired
    @LoggerInfo(operateDesc = LogDescConstant.DELETE_DEVELOPEROG_INFO_LOG_DESC)
    @RequestMapping(path = "delete",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteOperationLog(String logIds){
        MessageVO messageVO;
        try {
            HttpServletRequest request= ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            logIds=request.getAttribute("logIds")==null?null:request.getAttribute("logIds").toString();
            iOperateDeveloperLogServiceClient.delete(logIds);
            messageVO=new MessageVO(logIds, BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch(Exception e){
            throw new DataAccessException("【运营_日志管理_开发者日志delete】删除操作日志失败",e);
        }
        return messageVO;
    }
}
